package gov.pbc.nn.kjgl.task.handler;

import org.springframework.stereotype.Component;

import com.bstek.uflo.env.Context;
import com.bstek.uflo.model.ProcessInstance;
import com.bstek.uflo.process.handler.DecisionHandler;

@Component("gov.pbc.nn.kjgl.task.handler.TaskManagerDecisionHandler")
public class TaskManagerDecisionHandler implements DecisionHandler {

	@Override
	public String handle(Context context, ProcessInstance pi) {
		boolean driectProcessor = (boolean) context.getProcessService()
				.getProcessVariable("driectProcessor", pi);
		boolean needBranch = (boolean) context.getProcessService()
				.getProcessVariable("needBranch", pi);
		boolean collectOpinion = (boolean) context.getProcessService()
				.getProcessVariable("collectOpinion", pi);

		Object agreeObj = context.getProcessService().getProcessVariable(
				"agree", pi);
		boolean agree = agreeObj == null ? false : (boolean) agreeObj;

		Object reCollectOpinionObj = context.getProcessService()
				.getProcessVariable("reCollectOpinion", pi);
		boolean reCollectOpinion = reCollectOpinionObj == null ? false
				: (boolean) reCollectOpinionObj;

		Object hasCollectedObj = context.getProcessService()
				.getProcessVariable("hasCollected", pi);
		boolean hasCollected = hasCollectedObj == null ? false
				: (boolean) hasCollectedObj;

		if (driectProcessor) {
			// 直接指定了任务处理人
			return "to 处理人处理任务";
		}
		if (!collectOpinion) {
			// 需要分办，没有收集意见
			return "to 分办人动态分支";
		}
		if (agree && hasCollected) {
			// 需要分办，需要收集意见，内部审核通过，已经收集意见
			return "to 分办人动态分支";
		}
		if (agree && !hasCollected) {
			// 需要分办，需要收集意见，内部审核通过，尚未收集意见
			return "to 科长初步意见";
		}
		if (reCollectOpinion) {
			// 需要分办，需要收集意见，内部审核未通过，需要再次收集意见
			return "to 科长初步意见";
		}
		return null;
	}
}
